package hczc.longcai.com.hccrowdfunding.home.first_index.adapters;

import android.content.Context;
import android.net.Uri;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

import hczc.longcai.com.hccrowdfunding.R;
import hczc.longcai.com.hccrowdfunding.application.BaseApplication;
import hczc.longcai.com.hccrowdfunding.home.first_index.beans.ProjectInfo;
import hczc.longcai.com.hccrowdfunding.utils.bitmaputils.ImageLoader;

/**
 * Created by Administrator on 2016/1/13.
 */
public class IndexHotAdapter extends BaseAdapter {

    private static final String TAG = "IndexHotAdapter";
    private Context context;
    private List<ProjectInfo> list;
    private ImageLoader imageLoader;


    public IndexHotAdapter(Context context, List<ProjectInfo> list, ImageLoader imageLoader) {
        this.context = context;
        this.list = list;
        this.imageLoader = imageLoader;
    }



    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHoler holer = null;
        if (view == null) {
            holer = new ViewHoler();
            view = LayoutInflater.from(context).inflate(R.layout.item_index_hot, null);
            BaseApplication.scaleScreenHelper.loadView(((ViewGroup) view));
            holer.tab = ((TextView) view.findViewById(R.id.index_hot_listview_tab));
            holer.title = ((TextView) view.findViewById(R.id.index_hot_listview_title));
            holer.isLike = ((ImageView) view.findViewById(R.id.index_hot_listview_like));
            holer.pic = ((SimpleDraweeView) view.findViewById(R.id.index_hot_listview_pic));
            int width = holer.pic.getWidth();
            int height = holer.pic.getHeight();
            Log.d(TAG,"width = " + width + ",height = " + height);
            holer.money = ((TextView) view.findViewById(R.id.index_hot_listview_money_money));
            holer.eachMoney = ((TextView) view.findViewById(R.id.index_hot_listview_money_eachmoney));
            holer.people = ((TextView) view.findViewById(R.id.index_hot_listview_plan_people));
            holer.plan = ((TextView) view.findViewById(R.id.index_hot_listview_plan));
            holer.day = ((TextView) view.findViewById(R.id.index_hot_listview_plan_time));
            holer.details = ((TextView) view.findViewById(R.id.index_hot_listview_details));
            holer.dislike = ((TextView) view.findViewById(R.id.index_hot_listview_dislike));
            view.setTag(holer);
        }
        ProjectInfo projectInfo = list.get(i);
        holer = ((ViewHoler) view.getTag());
        String type = projectInfo.getType();
        String name = projectInfo.getName();
        String money = projectInfo.getMoney();
        String has_borrow = projectInfo.getHas_borrow();
        String time = projectInfo.getTime();
        String img = projectInfo.getImg();
//        holer.pic.setTag(img);
        holer.pic.setImageURI(Uri.parse(img));
        String duration = projectInfo.getDuration();
        String rate = projectInfo.getRate();
        String progress = projectInfo.getProgress();
        String info = projectInfo.getInfo();
        String status = projectInfo.getStatus();

        String day = duration + "个月收益" + rate;
        holer.tab.setText(type);
        holer.title.setText(name);
        holer.money.setText(money);
        holer.eachMoney.setText(has_borrow);
        holer.people.setText(time);
        holer.plan.setText(progress);
        holer.day.setText(day);


//        imageLoader.load(view, img, " From:IndexHotAdapter" + i);


        if (info != null) {
            holer.details.setText(info);
        }


        return view;
    }




    class ViewHoler {
        TextView tab, title, money, eachMoney, people, plan, day, details, dislike;
        ImageView isLike;
        SimpleDraweeView pic;
    }
}
